home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # PrGeneralPlayPrint.c
- #
- # This file contains all of the functions that are used at print time and the
- # calls to set the requested PrGeneral opcodes selected by the user via the
- # PrGeneral menu.
- #
- # We will test for the presence of PrGeneral at init time and any time the user
- # changes the printer driver. If PrGeneral is NOT available for the current
- # printer driver, the printer driver will return resNotFound in PrError. We
- # will disable the PrGeneral menu and call PrSetError(0), which will remove the
- # resNotfound error and allow PrGeneralPlay to print without using PrGeneral's
- # opcodes. We will set the gPrGeneralLives flag to false which will prevent us
- # from calling any of PrGeneral's opcodes.
- #
- # We assume that all of PrGeneral's opcodes are supported by the current printer
- # driver until we determine otherwise. If we try to use an unsupported opcode,
- # PrGeneral will set iError to OpNotImpl. We will then set one of the appropriate
- # flags (gLandscapeOpImpl, gDraftBitsOpImpl,or gSetRslOpImpl) to "false" to prevent
- # continued use of this opcode and adjust the PrGeneral menu appropriately. These
- # flags will be reset, if the user selects a new printer driver.
- #
- # If the "high resolution printing" menu item is selected, we use the GetRslData
- # opcode to determine the highest "square" resolution that is supported by the
- # current printer driver. Before we call SetRsl to set these new resolutions,
- # we will save the original resolutions (in gOriginaliVRes and gOriginaliHRes)
- # which will enable us to reset the resolutions to their original settings, when
- # the user turns "off" this menu item.
- #
- # When the user selects the "forced draft mode printing" menu item, we will create
- # an off-screen world, call drawStuff to draw our graph into it, and CopyBits the
- # contents into the printer's GrafPort. This will ensure that graph will print in
- # "draft" mode. Remember, when the DraftBits opcode is used, you will only be able
- # to print text, bitmaps, and pixmaps.
- #
- # When the "forced draft mode printing" menu item is turned "off", we use the
- # NoDraftBits opcode to turned off the effects of the DraftBits opcode.
- #
- # If the user has selected the "check for landscape orientation" menu item, we will
- # check to determine, if the landscape orientation was selected in the stlye dialog.
- # We will present the results of the landscape orientation check (GetRotn opcode)
- # via a dialog. We will only check for landscape orientation after the user calls
- # the Page Setup dialog.
- #
- # If any print error occurs during print time, we will call the AlertUser
- # function. This function will display an alert to tell the user that an
- # error occurred. This function is NOT how a "real" application should
- # handle printing errors, but it is the simplest approach possible for this
- # type of application. Our intent is to demonstrate the use of PrGeneral,
- # not to create a full featured application. Tech Note #161 contains an
- # industrial strength full featured printing loop.
- #
- # ------------------------------------------------------------------------------
- #
- # Versions: 1.00 June 1, 1990
- #
- # Components: PrGeneralPlay.c June 1, 1990
- # PrGeneralPlayPrint.c June 1, 1990
- # PrGeneralPlay.h June 1, 1990
- # PrGeneralPlay.r June 1, 1990
- #
- #
- # Apple Macintosh Developer Technical Support
- # Copyright © 1990 Apple Computer, Inc.
- # All rights reserved.
- #
- ------------------------------------------------------------------------------*/
-
- #include <Errors.h>
- #include <Types.h>
- #include <Resources.h>
- #include <ToolUtils.h>
- #include <QuickDraw.h>
- #include <QDOffscreen.h>
- #include <Fonts.h>
- #include <Printing.h>
- #include <Packages.h>
- #include <Memory.h>
- #include <sane.h>
- #include <PrGeneralPlay.h>
-
- // The following extern globals are set up by the Initialize function in PrGeneralPlay.c
-
- extern THPrint gPrRecHdl;
- extern Boolean gHighResolutionON,
- gUseDraftBits,
- gCheckForLandscape,
- gDraftBitsHasBeenSet;
- gPrGeneralLives,
- gLandscapeOpImpl,
- gDraftBitsOpImpl,
- gSetRslOpImpl;
-
- extern short gOriginalDriverVers;
-
- short gScale = 1,
- gMaxDPI = 0,
- gOriginaliVRes,
- gOriginaliHRes;
-
-
- void noPrGeneralAlert ( void );
- Boolean testForPrGeneral ( void );
- void saveResolution ( void );
- void resetSetRsl ( void );
- int setMaxResolution ( void );
- void doSetRsl ( void );
- void doDraftBits ( void );
- void doNODraftBits ( void );
- void drawStuff (GrafPtr prPort, short gScale);
- void copyBitsMyGraph (TPPrPort printPort);
- void comparePrintRecords ( void );
- void PresentStyleDialog ( void );
- void PrintThis( void );
-
-
- //------ noPrGeneralAlert -----------------------------------------------------------
- //
- // Display the alert that tells the user that PrGeneral is not available
- // for the currently selected printer driver...
- //
-
- void noPrGeneralAlert ()
- {
- short itemHit;
-
- SetCursor(&qd.arrow);
-
- itemHit = NoteAlert(rNOPrGeneralAlert, nil);
- } // end of noPrGeneralAlert
-
-
-
-
- //------ testForPrGeneral -----------------------------------------------------------
- //
- // We want to determine if PrGeneral is available. If it is not, the printer driver
- // will return resNotFound in PrError. We will then clear the error in PrError with
- // PrSetError (0) and proceed with printing without PrGeneral's opcodes. If we did not
- // clear the error, you would receive the error in PrError when it was checked, thereby
- // preventing your app from printing.
-
- Boolean testForPrGeneral ()
- {
- TGetRotnBlk GetRotRec;
- short printErr = 0;
-
- GetRotRec.iOpCode = getRotnOp; // We will test for PrGeneral with the landscape opcode...
- GetRotRec.hPrint = gPrRecHdl;
-
- PrGeneral ((Ptr) &GetRotRec);
-
- printErr = PrError ();
-
- if (printErr == noErr) // PrGeneral is supported by the current driver...
- return (true);
- else
- {
- if (printErr == resNotFound)
- {
- PrSetError (noErr); // Since PrGeneral is not available, we want to clear PrError,
- noPrGeneralAlert (); // which will enable your app to keep printing without
- return (false); // PrGeneral's opcodes...
- }
- else
- {
- PrClose ();
- AlertUser (); // Another type of print error occurred, therefore AlertUser
- }
- }
- } // end of testForPrGeneral
-
-
-
- //------ saveResolution -------------------------------------------------------------
- //
- // We need to save the original resolution of the current printer driver, which will
- // enable us to reset the resolutiuon if the user turns the "high resolution" printing
- // menu item "off".
- //
-
- void saveResolution ()
- {
- gOriginaliVRes = (**gPrRecHdl).prInfo.iVRes;
- gOriginaliHRes = (**gPrRecHdl).prInfo.iHRes;
- }
-
-
-
- //------ resetSetRsl ----------------------------------------------------------------
- //
- // resetSetRsl will reset the resolution of the print handle, back to it's orginal
- // before using the SetRsl opcode. If the user has not changed the printer, we
- // will reset the resolution of the printer driver with a call to the SetRsl opcode
- // with the orginal resolutions that were saved by the function saveResolution. If
- // the user has selected a different printer via the Chooser, we will call PrintDefault
- // on our print record.
- //
-
- void resetSetRsl ()
- {
- TSetRslBlk setResRec;
- THPrint localPrRecHdl;
- short latestDriverVers;
-
- // Create a "new" print record to compare with...
-
- localPrRecHdl = (THPrint) NewHandle(sizeof(TPrint));
- if (MemError() == noErr && localPrRecHdl != nil)
- {
- PrintDefault (localPrRecHdl);
-
- latestDriverVers = PrDrvrVers ();
-
- // We need to determine if the user changed the printer driver via Chooser.
- // Which would be a problem because the resolutions might not match across
- // different printer drivers. We also check to see if the version number has
- // changed, which will insure that the user did not change the printer driver
- // to a different printer driver version. This is important, because earlier
- // versions of the ImageWriter (i.e. before v2.5) did not support PrGeneral.
- // If they have changed the printer driver, call PrintDefault on our global print
- // record handle to update it.
-
- if ((((**gPrRecHdl).prStl.wDev) >> 8) == (((**localPrRecHdl).prStl.wDev) >> 8)
- || (latestDriverVers == gOriginalDriverVers))
- {
- // Reset the print record to the original resolutions...
-
- setResRec.iOpCode = setRslOp;
- setResRec.hPrint = gPrRecHdl;
-
- setResRec.iXRsl = gOriginaliHRes;
- setResRec.iYRsl = gOriginaliVRes;
-
-
- // We do not need to check any PrGeneral errors. Why? We know that this opcode
- // is supported and we are not using an unsupported resolution...
-
- PrGeneral ((Ptr)(&setResRec));
-
- gScale = 1;
- gMaxDPI = gOriginaliHRes;
-
- if (PrError () != noErr)
- {
- PrClose (); // We received an error in PrError after calling PrGeneral.
- AlertUser (); // Therefore, close the Print Manager and alert the user.
- }
- }
- else PrintDefault (gPrRecHdl);
-
- if (localPrRecHdl != nil) DisposHandle((Handle) localPrRecHdl);
- }
-
- // An error occurred allocating new print record, close the Print Manager and alert the user
- else
- {
- PrClose ();
- AlertUser();
- }
-
- } // end of resetSetRsl
-
-
-
-
- //------ setMaxResolution -----------------------------------------------------------
- //
- // setMaxResolution will find the highest "square" resolution supported by the currently
- // selected printer driver and set the Print Manager's GrafPort to this resolution.
- // This will enable high resolution printing using the standard Quickdraw calls. We
- // will return the resolution that is found by our calls to GetRslData. If the
- // GetRslData and/or SetRsl opcodes are not supported by the currently selected printer
- // driver, we will return 0. Which tells the calling function that it must use a
- // scale factor of 1 and assume no SetRsl support
- //
-
- int setMaxResolution ()
- {
- int resIndex;
-
- TGetRslBlk getResRec;
- TSetRslBlk setResRec;
-
- // Save the current resolution values from the iVRes and iHres fields from
- // the PrJob record; which enables us to reset the print handle with the original
- // values, if the user un-checks the "high resolution" menu item.
-
- saveResolution ();
-
- getResRec.iOpCode = getRslDataOp;
- PrGeneral ((Ptr)(&getResRec));
-
- // We have an array of possible resolutions.
- // After checking for errors, we loop through each resolution
- // range record looking for the highest resolution available, where x and
- // y are equal. This loop makes no assumptions about the order of the
- // resolution records. Find the maximum resolution supported by the current selected device.
- // Some devices support non-square aspect ratios (i.e. x-res != y-res), we
- // need to find the largest "square" resolution supported. The last rgRslRec is
- // the "highest" supported resolution record for all of the Apple printer drivers.
-
- if (getResRec.iError == noErr && PrError() == noErr)
- {
- for (resIndex = 0; resIndex < getResRec.iRslRecCnt ; resIndex++)
- {
- if ( getResRec.rgRslRec[resIndex].iXRsl ==
- getResRec.rgRslRec[resIndex].iYRsl &&
- getResRec.rgRslRec[resIndex].iXRsl > gMaxDPI)
-
- gMaxDPI = getResRec.rgRslRec[resIndex].iYRsl;
- }
-
- // We now have the desired resolution. If it is not 0, then we
- // use the SetRsl opcode to set the resolution.
-
- if (gMaxDPI != 0 && gPrRecHdl != nil)
- {
- setResRec.iOpCode = setRslOp;
- setResRec.hPrint = gPrRecHdl;
-
- setResRec.iXRsl = gMaxDPI;
- setResRec.iYRsl = gMaxDPI;
-
- PrGeneral ((Ptr)(&setResRec));
- }
- }
- // If the current printer driver does NOT support GetRslData set the flag
- // and return 0, which tells the calling function to use a scale factor of 1.
-
- else if (getResRec.iError == OpNotImpl)
- {
- gSetRslOpImpl = false;
- return (0);
- }
- else AlertUser ();
-
-
- // If our call to SetRsl worked return the "new" resolution, otherwise
- // check to see if this opcode is implemented. If it is not return 0
- // and set our SetRslOpImpl flag to false.
-
- if (setResRec.iError == noErr && PrError() == noErr && gMaxDPI != 0)
- return (gMaxDPI);
- else if (setResRec.iError == OpNotImpl && PrError() == noErr)
- {
- gSetRslOpImpl = false;
- return (0);
- }
- else return (0);
-
- } // end of setMaxResolution
-
-
-
-
- //------ doSetRsl -------------------------------------------------------------------
- //
- // doSetRsl is the calling function that calls setMaxResolution. setMaxResolution
- // will return the maximum resolution that is supported by the current printer
- // driver. With this device resolution (deviceRes), we will then determine the scale
- // factor that must be used on all of our coordinates and font sizes, otherwise
- // we will receive "micro" text and images. If setMaxresolution returns 0, it means
- // that SetRsl and GetRslData are not supported or an error occurred. We will then
- // use a scale factor of 1.
- //
-
- void doSetRsl ()
- {
- short deviceRes;
- GrafPtr oldPort;
-
- GetPort (&oldPort);
-
- deviceRes = setMaxResolution ();
-
- // If deviceRes is not zero, we will determine the scale factor that
- // MUST be used on all of our coordinates and font sizes. If we do
- // NOT scale these items, we will get the "micro" text and images...
-
- if (deviceRes != 0) gScale = deviceRes / MacScreenRes;
-
- SetPort (oldPort);
-
- } // end of doSetRsl
-
-
-
-
- //------ doDraftBits ----------------------------------------------------------------
- //
- // doDraftBits will set the draftBitsOp opcode for the current printer driver. If the
- // current printer driver does NOT support this opcode, we will set the gDraftBitsOpImpl
- // flag to false which will prevent this function from being called. If any error occurs,
- // we will alert the user via the AlertUser function.
- //
-
- void doDraftBits ()
- {
- TDftBitsBlk draftBitsBlk;
-
- gDraftBitsHasBeenSet = true;
-
- // Set the draftBitsOp and update the contents of the print handle.
-
- draftBitsBlk.iOpCode = draftBitsOp;
- draftBitsBlk.hPrint = gPrRecHdl;
- PrGeneral((Ptr) &draftBitsBlk);
-
- // The draftBits opcode is NOT supported by the current printer driver,
- // therefore we will set the draftBits opcode implemented flag to false.
- // Which will prevent this function from being called until a new printer
- // is selected via the Chooser. If another type of error occurred report
- // it to the user via AlertUser.
-
- if (draftBitsBlk.iError == OpNotImpl && PrError() == noErr)
- gDraftBitsOpImpl = false;
- else if (draftBitsBlk.iError != noErr || PrError() != noErr)
- AlertUser ();
-
- } // end of doDraftBits
-
-
-
-
- //------ doNODraftBits ---------------------------------------------------------------
- //
- // doNODraftBits will undo the call to set the draftBitsOp opcode. This function can
- // NOT be called if doDraftBits was not called or this opcode is not supported by the
- // current printer driver. This function behaves in the same manner as described above
- // for doDraftBits.
- //
-
- void doNODraftBits ()
- {
- TDftBitsBlk draftBitsBlk;
-
- draftBitsBlk.iOpCode = noDraftBitsOp;
- draftBitsBlk.hPrint = gPrRecHdl;
- PrGeneral((Ptr) &draftBitsBlk);
-
- if (draftBitsBlk.iError != noErr || PrError() != noErr)
- AlertUser ();
-
- } // end of doNODraftBits
-
-
-
-
- //------ ShowLandscapeResults --------------------------------------------------------
- //
- // This routine will show the results via a dialog of the IsLandscapeSet function.
- //
-
- void ShowLandscapeResults (Boolean result)
-
- {
- short itemHit;
- StringHandle displayMessage;
- Str255 displayMessageString;
-
- SetCursor(&qd.arrow);
-
- if (result)
- displayMessage = GetString (201);
- else
- displayMessage = GetString (202);
-
-
- if (displayMessage != nil)
- BlockMove(*displayMessage, &displayMessageString, (long)*displayMessage[0]+1L);
- else
- AlertUser();
-
- ParamText (displayMessageString, "\p ", "\p ", "\p ");
-
- itemHit = NoteAlert(rLandscapeAlert, nil);
-
- } // end of ShowLandscapeResults
-
-
-
-
- //------ IsLandscapeSet -------------------------------------------------------------
- //
- // IsLandscapeSet will determine if the user has selected landscape orientation
- // from the Style dialog. If the user has selected landscape orientation, we will
- // return "true" to the calling function. Otherwise, return "false".
- //
-
- void IsLandscapeSet (THPrint thePrRecHdl)
-
- {
- TGetRotnBlk GetRotRec;
-
- GetRotRec.iOpCode = getRotnOp;
- GetRotRec.hPrint = thePrRecHdl;
-
- PrGeneral ((Ptr) &GetRotRec);
-
- // If the landscape opcode is NOT implemented by the current printer driver,
- // set the flag to true. This flag will preent the calling of this function
- // until the printer driver is changed...
-
- if (GetRotRec.iError == OpNotImpl)
- gLandscapeOpImpl = false;
-
-
- // We now have the result from our call to PrGeneral, but we check all
- // known errors to make sure that PrGeneral was successful and there
- // have not been any errors encountered from printing land.
-
- if (GetRotRec.iError == noErr && PrError() == noErr && GetRotRec.fLandscape)
- ShowLandscapeResults (true);
- else if (GetRotRec.iError != OpNotImpl)
- ShowLandscapeResults (false);
-
- } // end of IsLandscapeSet
-
-
-
-
- //------ drawStuff ------------------------------------------------------------------
- //
- // drawStuff will create the graph and draw it directly to the current port that is
- // passed in via the prPort variable. It will draw all of the coordinates and font
- // sizes at the prScale value. For example, on the ImageWriter, the scaling is 2X
- // the screen. On the ImageWriter LQ, three times and on the LaserWriter, four times.
- // TBy using a scale factor ensures that you do NOT print "micro" images or text when
- // the SetRsl opcode is used.
- //
- // The number of line segments used to draw our graph is is directly proportional to
- // the gScale factor (i.e. prScale), which is why you will get smoother curves when
- // using the SetRsl opcode on any printer driver that supports it. For example, on
- // the LaserWriter II/NT the gScale factor is 4; which means for a given line segment
- // in the curve, you will have 3 additional points when printing with SetRsl.
- //
-
- void drawStuff ( prPort, prScale)
-
- GrafPtr prPort;
- short prScale;
- {
- short theFontID;
- Rect graphRect;
-
- short loop,
- plotX,
- plotY;
-
- extended x = -2.5,
- y;
- Str255 scaleValueStr;
-
- CGrafPtr currPort;
- GDHandle currDev;
-
-
- GetGWorld (&currPort, &currDev);
-
- SetGWorld ((CGrafPtr) prPort, currDev);
-
- SetRect (&graphRect, 0, 0, 500, 300);
-
- EraseRect (&(prPort->portRect));
-
-
- // Print the heading of the graph...
-
- GetFNum("\pHelvetica", &theFontID);
- TextFont(theFontID);
- TextSize (FontSize * prScale);
- MoveTo ( 120 * prScale, 55 * prScale);
- DrawString ("\pPrinting at ");
-
- if (gMaxDPI == 0)
- NumToString ((**gPrRecHdl).prInfo.iHRes, &scaleValueStr);
- else NumToString (gMaxDPI, &scaleValueStr);
-
- DrawString (scaleValueStr);
-
- MoveTo (201 * prScale , 55 * prScale);
- DrawString ("\pdpi");
-
-
- // Draw the axes of the graph...
-
- PenSize(2 * prScale, 1 * prScale);
-
- MoveTo ((graphRect.left + 20) * prScale, (graphRect.top + 45) * prScale);
- LineTo ((graphRect.left + 20) * prScale, (graphRect.bottom - 45) * prScale);
- MoveTo ((graphRect.left + 20) * prScale, ((graphRect.bottom - graphRect.top)/2) * prScale);
- LineTo ((graphRect.right - 170) * prScale, ((graphRect.bottom - graphRect.top)/2) * prScale);
-
-
- // Draw the lower curve...
-
- MoveTo ((graphRect.left + 20) * prScale, ((graphRect.bottom - graphRect.top)/2) * prScale);
- PenSize(1,1);
-
- plotX = (graphRect.left + 20) * prScale;
- plotY = ((graphRect.bottom - graphRect.top - 85)/2) * prScale;
-
-
- // The number of line segments is directly proportional to the gScale factor (i.e. prScale),
- // which is why you will get smoother curves when using the SetRsl opcode on any printer
- // driver that supports it. For example, on the LaserWriter II/NT the gScale factor is 4;
- // which means for a given line segment in the curve, you will have 3 additional points
- // when printing with SetRsl.
-
- for (loop = 1; loop < 20 * prScale; loop++)
- {
- y = (sin (x/2)) * 35 + 2;
-
- plotY = (plotY + ((int) y));
- plotX = (plotX + ((int) x));
-
- if (plotX >= (graphRect.left + 22) * prScale)
- LineTo (plotX, plotY);
-
- plotX += 10;
-
- x += 1.0 / (float) prScale;
- }
-
-
- // Draw the lower curve
- x = 0;
-
- MoveTo ((graphRect.left + 20) * prScale, ((graphRect.bottom - graphRect.top)/2) * prScale);
-
- plotX = (graphRect.left + 20) * prScale;
- plotY = ((graphRect.bottom - graphRect.top - 60)/2) * prScale;
-
- for (loop = 1; loop < 18 * prScale; loop++)
- {
- y = (cos (x/2)) * 40 + 2;
-
- plotY = (plotY + ((int) y));
- plotX = (plotX + ((int) x));
-
- if (plotX >= (graphRect.left + 22) * prScale)
- LineTo (plotX, plotY);
-
- plotX += 10;
-
- x += 1.0 / (float) prScale;
- }
-
- SetGWorld (currPort, currDev);
-
- } // end of drawStuff
-
-
-
-
- //------ copyBitsMyGraph -------------------------------------------------------------
- //
- // copyBitsMyGraph will create a off-screen world with a call to 32-bit QuickDraw's
- // NewGWorld. We check to make sure that 32-bit QuickDraw is present BEFORE this
- // function is called. We will then draw directly into the the off-screen world with a call
- // to drawStuff. CopyBits will then be used to copy the contents of the off-screen world
- // into the printer's GrafPort. Remember, when you use the DraftBits opcode, it will
- // only print text, bitmaps, and pixmaps. If we did NOT use the CopyBits call, only the
- // heading of the graph would be printed...
- //
-
- void copyBitsMyGraph (TPPrPort printPort)
- {
- Rect graphRect;
- QDErr QDError;
- GDHandle currDev;
- CGrafPtr currPort;
- GWorldPtr myDrawingPort;
-
-
- GetGWorld (&currPort, &currDev);
-
- SetRect (&graphRect, 0, 0, 500 * gScale, 300 * gScale);
-
- QDError = NewGWorld(&myDrawingPort, 1, &graphRect, nil, nil, 0);
-
- if (QDError == noErr)
- {
- if (!LockPixels (myDrawingPort->portPixMap))
- AlertUser ();
-
- // Draw the graph into the off-screen world...
- drawStuff (myDrawingPort, gScale);
-
-
- // Set the port to the printer's GrafPort and CopyBits the off-screen
- // world into the printer's GrafPort.
-
- SetPort (&(printPort->gPort));
- CopyBits ((BitMap *) &myDrawingPort->portPixMap, &(printPort->gPort.portBits),
- &myDrawingPort->portRect, &myDrawingPort->portRect, srcCopy, nil);
- UnlockPixels (myDrawingPort->portPixMap);
-
- }
- else AlertUser ();
-
- if (myDrawingPort != nil)
- DisposeGWorld (myDrawingPort);
-
- SetGWorld (currPort, currDev);
-
- } // end of copyBitsMyGraph
-
-
-
-
-
- //------ comparePrintRecords ---------------------------------------------------------
- //
- // We need to determine if the print has changed, since the last time we
- // called the PageSetup or Print Job dialog. If it has, we want to update the print
- // record with the PrGeneral selections from the PrGeneral menu. But, before we call
- // PrGeneral to set the requested opcodes, we will call testForPrGeneral to make sure
- // that it is supported by the "new" printer driver. We only worry about the SetRsl and
- // DraftBits opcodes at this point, because they effect the appearance of the PageSetup
- // and Print Job, if PrGeneral is available.
- //
-
- void comparePrintRecords ()
- {
- THPrint localPrRecHdl;
- short latestDriverVers;
-
-
- // Create a new print record with default settings
-
- localPrRecHdl = (THPrint) NewHandle(sizeof(TPrint));
- if (MemError() == noErr && localPrRecHdl != nil)
- {
- PrintDefault (localPrRecHdl);
-
- latestDriverVers = PrDrvrVers ();
-
- // This is an example of the right place to use wDev. We are only using wDev to
- // determine, if the print records are the same type. NOT to check for specific
- // functionality which would be a bad idea for compatibility with unknown printers.
-
- if (PrError () == noErr)
- {
- if ((((**gPrRecHdl).prStl.wDev) >> 8) != (((**localPrRecHdl).prStl.wDev) >> 8)
- || (latestDriverVers != gOriginalDriverVers))
- {
- // Set the print record to default settings for the "new" printer...
-
- PrintDefault (gPrRecHdl);
-
- // Reset the value of gOriginalDriverVers
-
- gOriginalDriverVers = latestDriverVers;
-
-
- // Reset gMaxDPI to enable the loop in setMaxResolution to find the correct
- // maximum resolution
-
- gMaxDPI = 0;
-
-
- // Reset all of the opcode implementation flags. We now have a new printer
- // driver, therefore we need to determine which opcodes are supported.
-
- gLandscapeOpImpl = true;
- gDraftBitsOpImpl = true;
- gSetRslOpImpl = true;
-
-
- // Test to determine, if the "new" printer driver supports PrGeneral before
- // updating the print record with the requested PrGeneral opcodes...
-
- if (PrError () == noErr)
- gPrGeneralLives = testForPrGeneral ();
- else AlertUser ();
-
-
- // Call the appropriate PrGeneral opcodes, determined by the PrGeneral menu...
-
- if (PrError () == noErr && gPrGeneralLives)
- {
- if (gUseDraftBits && gDraftBitsOpImpl) doDraftBits();
-
- if (gHighResolutionON && gSetRslOpImpl) doSetRsl();
- }
- }
-
- if (localPrRecHdl != nil) DisposHandle((Handle) localPrRecHdl);
- }
-
- // An error has occurred, close the Print Manager and alert the user
-
- else
- {
- PrClose ();
- if (localPrRecHdl != nil) DisposHandle((Handle) localPrRecHdl);
- AlertUser ();
- }
- }
-
- // An error occurred allocating new print record, close the Print Manager and alert the user
- else
- {
- PrClose ();
- AlertUser();
- }
-
- } // end of comparePrintRecords
-
-
-
-
- //------ PresentStyleDialog ----------------------------------------------------------
- //
- // We will present the PageSetup dialog requested by the user, but we want to make sure
- // that the printer driver has not changed. Why? If the user has changed the printer
- // driver via the Chooser, we want to update the print record with the requested
- // PrGeneral opcodes, if the "new" (current) printer driver supports PrGeneral.
- // Remember, the SetRsl and DraftBits opcodes change the appearence of the Page Setup
- // dialog, therefore we want to make the PrGeneral calls before presenting the dialog.
- //
-
- void PresentStyleDialog ()
- {
- if ( gPrRecHdl )
- {
- PrOpen();
-
- // A print error occurred, close up the Print Manager and notify the user...
-
- if (PrError () != noErr)
- {
- PrClose();
- AlertUser ();
- }
- else
- {
- // Check to make sure that the user has not changed the printer driver
-
- comparePrintRecords ();
-
- PrStlDialog(gPrRecHdl);
-
- // Check for landscape orientation, if the user has requested the test via
- // the PrGeneral Menu and PrGeneral exists for the current printer driver...
-
- if (gCheckForLandscape && gPrGeneralLives && gLandscapeOpImpl)
- IsLandscapeSet (gPrRecHdl);
-
- PrClose();
- }
- }
- else AlertUser (); // The gPrRecHdl is nil and it should not be, alert the user
-
- } // end of PresentStyleDialog
-
-
-
-
- //------ PrintThis -------------------------------------------------------------------
- //
- // PrintThis is your basic print loop. If any error occurs during this function
- // (i.e. print time) the user will be notified via a call to AlertUser. But, before we
- // alert the user, we will call the corresponding close call(s) for all of the open
- // call(s) (i.e. PrOpenDoc --> PrCloseDoc) and close up the Print Manager. For a
- // complete industrial strength print loop, see Tech Note #161.
- //
-
- void PrintThis()
- {
- short NumberOfPages;
- TPPrPort printPort;
- OSErr err;
- short i;
- TPrStatus Status;
- GDHandle currDev;
- CGrafPtr currPort;
-
- GetGWorld (&currPort, &currDev);
-
- if ( gPrRecHdl ) {
- PrOpen();
- if ( PrError() == noErr ) {
-
- // Determine if the printer driver has changed...
-
- comparePrintRecords ();
-
- if ( PrJobDialog(gPrRecHdl))
-
- if ( PrError() == noErr ) {
-
- NumberOfPages = (**gPrRecHdl).prJob.iCopies;
-
- printPort = PrOpenDoc(gPrRecHdl,nil,nil);
-
- if ( PrError() == noErr ) {
- for ( i = 1; i <= NumberOfPages; i++) {
- PrOpenPage(printPort,nil);
-
- if ( !(err = PrError()) ) {
-
- // If the user has selected the DraftBits menu item,
- // we will call copyBitsMyGraph, which will ensure that
- // our graph will be printed "draft" on the ImageWritter. If
- // we just called drawStuff all of the time, the graph would
- // NOT print when "draft" printing was selected.
-
- if (gUseDraftBits)
- copyBitsMyGraph (printPort);
- else drawStuff (&(printPort->gPort), gScale);
- }
-
- PrClosePage(printPort);
- }
- PrCloseDoc(printPort);
- }
-
- if ((**gPrRecHdl).prJob.bJDocLoop == bSpoolLoop && PrError() == noErr)
- PrPicFile(gPrRecHdl,nil,nil,nil,&Status);
-
- err = PrError();
-
- PrClose();
- if ( err )
- AlertUser();
- }
- }
- }
-
- SetGWorld (currPort, currDev);
-
- } // end of PrintThis
-